import java.util.ArrayList;
/**
 * Used to get data from the game such as gamemap size
 * playerpositions and what value each position of the
 * gamemap has. 
 * 
 * @author Patrik
 */

public class InfoInstruction implements InstructionInterface {

	IntWrapper param1;
	IntWrapper param2;
	IntWrapper param3;
	IntWrapper spelarId;
	
	/**
	 * parameters[0] defines what kind of gamedata that will
	 * be stored in parameters[0].
	 * if parameters[0]=1 stores sidelenght of the square Gamemap
	 * if parameters[0]=2 stores (x,y) position of the player with
	 * playerId specified with the last element in parameters. The
	 * data is stored in the first 2 IntWrappers in parameters.
	 * if parameters[0]=3 stores the value of a position (x,y) on the
	 * gamemap specified by the second and third element of parameters.
	 * @param parameters
	 */
	public InfoInstruction(ArrayList<IntWrapper> parameters){
		spelarId=parameters.get(parameters.size()-1);
		param1=parameters.get(0);
		if(parameters.size()>2){
			param2=parameters.get(1);
		}
		if(parameters.size()==4){
			param3=parameters.get(2);
		}
	}
	
	/**
	 * Depending on param1 different data is
	 * stored in param1
	 * @return null
	 */
	public Integer act() {
		if(param1.get()==1){
			param1.set(GameMap.getSideLength());
		}
		else if(param1.get()==2){
			int[] coordinates;
			coordinates=GameMap.getPlayerPosition(spelarId.get());
			param1.set(coordinates[0]);
			param2.set(coordinates[1]);
		}
		else if(param1.get()==3){
			param1.set(GameMap.getPosition(param2.get(),param3.get()));
		}
		return null;
	}

}
